#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAXARRAY 100
#define cycle for

const char* boo(const bool b) {
    return b ? "true" : "false";
}

void something(int a[], int i, int d, int g, int c, int b, int e, int f, int h[])
{
  cycle (i = 0; i < d; i++) 
  {
    if(strlen(boo(g <= c - b)) == 4)
      if(strlen(boo(f > e / 2 - b)) == 5)
       if(strlen(boo(h[f] > h[g])) == 4)
        a[i + b] = h[g++];
       else
        a[i + c] = h[f++];
      else
       a[i + b] = h[g++];
    else
      a[i + b] = h[f++];
  }
}
 
void sort(int a[], int b, int c) 
{
 int i, d, e, f, g;
  
 if(b == c)
  return;
 
 e  = b + c;
 
 sort(a, b, e / 2);
 sort(a, e / 2 + 1, c);
  
 d = c - b + 1;
 int h[d]; 
  
 cycle(i = 0; i < d; i++)
  h[i] = a[b + i];
 
 f = 0;
 g = e / 2 - b + 1;
 something(a, i, d, g, c, b, e, f, h);
}

 int main() 
{
 int array[MAXARRAY],n;
 int i = 0;
 
  printf("Enter the number of elements to be sorted:");
  scanf("%d",&n);
  printf("Enter the elements to be sorted:\n");
   for(i = 0; i < n; i++ ){
       scanf("%d",&array[i]);
   }
 
 printf("Before sorting:");
 for(i = 0; i < n; i++)
  printf(" %d", array[i]);
 
 printf("\n");
 
 sort(array, 0, n - 1);
 
 printf("After sorting:");
 for(i = 0; i < n; i++)
  printf(" %d", array[i]);
 
 printf("\n");
 return 0;
}

